//
//  LKChooseFileTypeViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/6/8.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKChooseFileTypeViewController.h"
#import "LKOrderEditBottomView.h"
#import "LKOrderEditTopView.h"
#import "LKUploadFileViewController.h"
#import "LKWorkOrderUpdateViewController.h"
#import "LKWorkOrderDetailViewController.h"
@interface LKChooseFileTypeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)LKOrderEditBottomView *bottomView;
@property(nonatomic,strong)NSMutableArray *valuesArray;
@property(nonatomic,strong)NSArray *titlesArray;

@end

@implementation LKChooseFileTypeViewController
-(LKBaseTableview *)tableview{
    if (!_tableview) {
        WS(weakSelf)
        _bottomView = [[[NSBundle mainBundle] loadNibNamed:@"LKOrderEditBottomView" owner:self options:nil] lastObject];
        [self.view addSubview:_bottomView];
        [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.view);
            make.height.mas_equalTo(69);
        }];
        [[_bottomView.forwardBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }];
        
        [[_bottomView.nextBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {

        }];
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT + 10, WIDTH , HEIGHT - NAVIGATION_BAR_HEIGHT - 10 - 70) style:UITableViewStylePlain registercellClasss:@[@"LKWorkOrderListDetailCell",@"LKWorkOrderListDetailPictureCell"]];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.backgroundColor = cellHeaderBgColor;
        _tableview.dataSource = self;
        _tableview.tableFooterView = [[UIView alloc] init];
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableview reloadData];
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"附件类型";
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titlesArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *arra = self.valuesArray[section];
    return arra.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *arra = self.valuesArray[indexPath.section];
    if (indexPath.row == arra.count - 1) {
        return 90;
    }
    return 43;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    LKOrderEditTopView *topView = [[[NSBundle mainBundle] loadNibNamed:@"LKOrderEditTopView" owner:self options:nil] lastObject];
    [topView.leftBtn setTitle:self.titlesArray[section] forState:UIControlStateNormal];
    [topView.leftBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [topView.rightBtn addTarget:self action:@selector(chooseBankCard:) forControlEvents:UIControlEventTouchUpInside];
    [topView.rightBtn setImage:[UIImage imageNamed:@"blueinArrow"] forState:UIControlStateNormal];
    [topView.rightBtn setTitle:@"" forState:UIControlStateNormal];
    topView.rightBtn.tag = 10000 + section;
    return topView;
}
-(void)chooseBankCard:(UIButton *)btn{
    LKUploadFileViewController *vc = [[LKUploadFileViewController alloc] init];
    vc.fileType = btn.tag - 10000;
    vc.addOrderModel = self.addOrderModel;
    [self.navigationController pushViewController:vc animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 43;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    LKUploadFileViewController *vc = [[LKUploadFileViewController alloc] init];
    vc.fileType = indexPath.section - 10000;
    [self.navigationController pushViewController:vc animated:YES];
}

-(NSMutableArray *)valuesArray{
    if (!_valuesArray) {
        _valuesArray = [[NSMutableArray alloc] init];
        [_valuesArray addObjectsFromArray:@[@[],@[]]];
    }
    return _valuesArray;
}

-(NSArray *)titlesArray{
    if (!_titlesArray) {
        _titlesArray = @[@"纸质合同",@"电子协议"];
    }
    return _titlesArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
